//
//  UserModel.m
//  Customer
//
//  Created by tangang on 2017/8/28.
//  Copyright © 2017年 tangang. All rights reserved.
//

#import "UserModel.h"

#define User_Info   @"user_info"

//static UserModel *u_model=nil;
@implementation UserModel
+ (UserModel *)userModel{
    UserModel *u_model=[[UserModel alloc]init];
    UserModel *dataModel=[UserModel mj_objectWithKeyValues:[[NSUserDefaults standardUserDefaults] objectForKey:User_Info]];
    u_model.UserId=dataModel.UserId;
    u_model.NickName=dataModel.NickName;
    u_model.pwd=dataModel.pwd;
    u_model.Mobile=dataModel.Mobile;
    u_model.Avater=dataModel.Avater;
    u_model.Account=dataModel.Account;
    return u_model;
}

+ (void)clean{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:User_Info];
}

+ (void)saveModel:(NSDictionary *)dict{
    [[NSUserDefaults standardUserDefaults] setObject:dict forKey:User_Info];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)setMobile:(NSString *)Mobile{
    if (Mobile) {
        NSMutableDictionary *dict =[self userDict];
        [dict setObject:Mobile forKey:@"Mobile"];
        [self saveModel:dict];
    }
}

+ (void)setPwd:(NSString *)pwd{
    if (pwd) {
        NSMutableDictionary *dict =[self userDict];
        [dict setObject:pwd forKey:@"pwd"];
        [self saveModel:dict];
    }
}

+ (void)setAvater:(NSString *)Avater{
    if (Avater) {
        NSMutableDictionary *dict =[self userDict];
        [dict setObject:Avater forKey:@"Avater"];
        [self saveModel:dict];
    }
}


+ (void)setPhone:(NSString *)phone andPassword:(NSString *)password andUserId:(NSString *)userId andUserName:(NSString *)userName andImg:(NSString *)img{
    [[NSUserDefaults standardUserDefaults] setObject:phone forKey:HistoryMoblie];
    [[NSUserDefaults standardUserDefaults] setObject:password forKey:HistoryPassword];
    NSMutableDictionary *dict =[self userDict];
    [dict setObject:phone forKey:@"Mobile"];
    [dict setObject:password forKey:@"pwd"];
    [dict setObject:userId forKey:@"UserId"];
    [dict setObject:userName forKey:@"NickName"];
    [dict setObject:img forKey:@"Avater"];
    [self saveModel:dict];
}


+ (NSMutableDictionary *)userDict{
    NSMutableDictionary *dict =[[[NSUserDefaults standardUserDefaults] objectForKey:User_Info] mutableCopy];
    if (!dict) {
        dict=[[NSMutableDictionary alloc]init];
    }
    return dict;
}

- (NSString *)MasterLottery{
    if (!_MasterLottery) {
        _MasterLottery=@"";
    }
    return _MasterLottery;
}

@end
